/**
 * 服务器端打包配置
 */
const webpack = require('webpack');
const path = require('path');
const nodeExternals = require('webpack-node-externals');

const config = require('../index');

module.exports = {
    name: 'server',
    
    target: 'node',

    entry: {
        app: [
            './src/server/index.js'
        ]
    },

    externals: [
        nodeExternals({
            whitelist: /\.css$/
        })
    ],

    output: {
        path: path.resolve(__dirname, '../../dist/server'),
        filename: 'server.js',
        publicPath: config.public_path + '/'
    },

    resolve: {
        alias: {
            '@': path.resolve('src'),
            Config: path.resolve('config/index')
        }
    },

    module: {
        rules: [
            {
                test: /\.(js?|css)$/,
                exclude: /node_modules/,
                loader: 'babel-loader'
            },

            // 图片文件
            {
                test: /\.(png|jpg|gif)$/,
                use: [
                    {
                        loader: 'url-loader',
                        options: {
                            limit: 10240
                        }
                    }
                ]
            },

            /**
             * 加载字体文件
             */
            {
                test: /\.(woff|woff2|eot|ttf|otf)$/,
                use: [
                    {
                        loader: 'file-loader',
                        options: {
                            limit: 10240
                        }
                    }
                ]
            },

            /**
             * 加载 css 文件
             */
            {
                test: /\.css$/,
                use: [
                    {
                        loader: require('styled-jsx/webpack').loader
                    }
                ]
            },
        ]
    },

    plugins: [
        new webpack.DefinePlugin({
            __SERVER__: 'true',
            __CLIENT__: 'false',
        })
    ]
}